<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The DateInterval class</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="datetimezone.listidentifiers.html">DateTimeZone::listIdentifiers</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="dateinterval.construct.html">DateInterval::__construct</a></div>
 <div class="up"><a href="book.datetime.html">Date/Time</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="class.dateinterval" class="reference">

 <h1 class="title">The DateInterval class</h1>
 

 <div class="partintro"><p class="verinfo">(PHP 5 &gt;= 5.3.0)</p>


  <div class="section" id="dateinterval.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    Represents a date interval.
   </p>
   <p class="para">
    A date interval stores either a fixed amount of time (in years, months,
    days, hours etc) or a relative time string in the format that
    <a href="class.datetime.html" class="classname">DateTime</a>&#039;s constructor supports.
   </p>
  </div>


  <div class="section" id="dateinterval.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">
     <span class="ooclass">
      <strong class="classname">DateInterval</strong>
     </span>
     {</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 属性 */</div>
    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="type">integer</span>
      <var class="varname"><a href="class.dateinterval.html#dateinterval.props.y">$<var class="varname">y</var></a></var>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="type">integer</span>
      <var class="varname"><a href="class.dateinterval.html#dateinterval.props.m">$<var class="varname">m</var></a></var>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="type">integer</span>
      <var class="varname"><a href="class.dateinterval.html#dateinterval.props.d">$<var class="varname">d</var></a></var>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="type">integer</span>
      <var class="varname"><a href="class.dateinterval.html#dateinterval.props.h">$<var class="varname">h</var></a></var>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="type">integer</span>
      <var class="varname"><a href="class.dateinterval.html#dateinterval.props.i">$<var class="varname">i</var></a></var>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="type">integer</span>
      <var class="varname"><a href="class.dateinterval.html#dateinterval.props.s">$<var class="varname">s</var></a></var>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="type">integer</span>
      <var class="varname"><a href="class.dateinterval.html#dateinterval.props.invert">$<var class="varname">invert</var></a></var>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span>
      <var class="varname"><a href="class.dateinterval.html#dateinterval.props.days">$<var class="varname">days</var></a></var>
    ;</div>

    
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="dateinterval.construct.html" class="methodname">__construct</a></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$interval_spec</code></span>
   )</div>

    
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">DateInterval</span><span class="methodname"><a href="dateinterval.createfromdatestring.html" class="methodname">createFromDateString</a></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$time</code></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">string</span><span class="methodname"><a href="dateinterval.format.html" class="methodname">format</a></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$format</code></span>
   )</div>


   }</div>


  </div>
  
  <div class="section" id="dateinterval.props">
   <h2 class="title">属性</h2>
   <dl>

    
     <dt id="dateinterval.props.y"><var class="varname"><var class="varname">y</var></var></dt>

     <dd>

      <p class="para">
       Number of years.
      </p>
     </dd>

    
    
     <dt id="dateinterval.props.m"><var class="varname"><var class="varname">m</var></var></dt>

     <dd>

      <p class="para">
       Number of months.
      </p>
     </dd>

    
    
     <dt id="dateinterval.props.d"><var class="varname"><var class="varname">d</var></var></dt>

     <dd>

      <p class="para">
       Number of days.
      </p>
     </dd>

    
    
     <dt id="dateinterval.props.h"><var class="varname"><var class="varname">h</var></var></dt>

     <dd>

      <p class="para">
       Number of hours.
      </p>
     </dd>

    
    
     <dt id="dateinterval.props.i"><var class="varname"><var class="varname">i</var></var></dt>

     <dd>

      <p class="para">
       Number of minutes.
      </p>
     </dd>

    
    
     <dt id="dateinterval.props.s"><var class="varname"><var class="varname">s</var></var></dt>

     <dd>

      <p class="para">
       Number of seconds.
      </p>
     </dd>

    
    
     <dt id="dateinterval.props.invert"><var class="varname"><var class="varname">invert</var></var></dt>

     <dd>

      <p class="para">
       Is <em>1</em> if the interval
       represents a negative time period and
       <em>0</em> otherwise.
       See <span class="methodname"><a href="dateinterval.format.html" class="methodname">DateInterval::format()</a></span>.
      </p>
     </dd>

    
    
     <dt id="dateinterval.props.days"><var class="varname"><var class="varname">days</var></var></dt>

     <dd>

      <p class="para">
       If the DateInterval object was created by
       <span class="function"><a href="datetime.diff.html" class="function">DateTime::diff()</a></span>, then this is the total number of
       days between the start and end dates. Otherwise,
       <var class="varname"><var class="varname">days</var></var> will be <strong><code>FALSE</code></strong>.
      </p>
      <p class="para">
       Before PHP 5.4.20/5.5.4 instead of <strong><code>FALSE</code></strong> you will receive -99999 upon
       accessing the property.
      </p>
     </dd>

    
   </dl>

  </div>

 </div>

 






















<h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="dateinterval.construct.html">DateInterval::__construct</a> — Creates a new DateInterval object</li><li><a href="dateinterval.createfromdatestring.html">DateInterval::createFromDateString</a> — Sets up a DateInterval from the relative parts of the string</li><li><a href="dateinterval.format.html">DateInterval::format</a> — Formats the interval</li></ul>
</div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="datetimezone.listidentifiers.html">DateTimeZone::listIdentifiers</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="dateinterval.construct.html">DateInterval::__construct</a></div>
 <div class="up"><a href="book.datetime.html">Date/Time</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
